package com.woniu.aiclient.config;

import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;

import com.woniu.aiclient.adviors.MyLoggerAdvisor;
import com.woniu.aiclient.memory.RedisChatMemory;
import com.woniu.aiclient.prompt.POIPrompt;
import com.woniu.aiclient.tools.MapServiceTools;
import jakarta.annotation.Resource;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.Arrays;
import java.util.Optional;

@Configuration
@Slf4j
public class AiChatClient {


    @Bean
    public ChatClient poiClient(@Qualifier("dashscopeChatModel")ChatModel model,
                                ToolCallbackProvider tools,
                                RedisChatMemory chatMemory


                                 ){

        ToolCallback[] toolCallbacks = tools.getToolCallbacks();

        DashScopeChatOptions build = DashScopeChatOptions.builder()
                .withEnableThinking(false).withTemperature(0.3).build();
        return  ChatClient.builder(model)
                .defaultOptions( build)
                .defaultAdvisors(new SimpleLoggerAdvisor(),
                        MessageChatMemoryAdvisor.builder(chatMemory).build())
                .defaultToolCallbacks(toolCallbacks)
                .build();
    }
    @Bean
    public ChatClient intentClient(@Qualifier("dashscopeChatModel")ChatModel model){
        return ChatClient.builder(model)
               .defaultAdvisors(new MyLoggerAdvisor())
               .build();
    }

//    @Bean
//    public ChatClient poiClient(@Qualifier("deepSeekChatModel")ChatModel model, MapServiceTools mapServiceTools,
//                                @Qualifier("javaMemory") ChatMemory chatMemory){
//        ToolCallback[] toolCallbacks = tools.getToolCallbacks();
//

//        for (ToolCallback toolCallback : toolCallbacks) {
//            System.out.println(toolCallback.getToolDefinition().description());
//        }
//        return  ChatClient.builder(model)
//                .defaultAdvisors(new MyLoggerAdvisor(),
//                        MessageChatMemoryAdvisor.builder(chatMemory).build())
//                .defaultTools(mapServiceTools)
//                .build();

//    }




}